package com.woori.taglib;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class CheckLoginHandler extends TagSupport {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
    public int doStartTag() throws JspException {
        JspWriter out = pageContext.getOut();
        HttpSession session = pageContext.getSession();
        try {
            String userid = (String)session.getAttribute("userid");
            //if user has been logged in, welcome!
            if(userid!=null){
            	out.println("Welcome "+userid+"!!");
            }else{
            	out.println("<form name=\"frmLogin\" action=\"./login.do\" method=\"post\">");
            	out.println("	id<input type=\"text\" name=\"userid\" value=\"\">"); 
            	out.println("	pw<input type=\"text\" name=\"password\" value=\"\"><br />"); 
            	out.println("	<input	type=\"submit\" value=\"login\">"); 
            	out.println("	<input type=\"reset\"	value=\"cancel\">");
            	out.println("</form>");
            }
            //else 
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SKIP_BODY;
    }
}
